import os

# 所有在脚本中会引用到的包,必须在这里导入一次,这样pyinstaller打包的时候才会打包进去
# import for script
from runtime.flow import *
from lib import browser
from lib import log
from lib import snapshot
from lib import excel
import win32
import datetime
import jinja2
import requests
import openpyxl
import xlrd
import selenium
import fitz
import cv2
import numpy
import PIL
import imutils
import docxtpl
import pdfplumber
import Crypto
import pyperclip
import pynput
import tkinter
import threading
import base64
import urllib
import json


EMBEDED_SCRIPTS = [

]

# def __include_embedded_script():
#     global EMBEDED_SCRIPTS
#     from scripts.fybq import export as fybq
#     EMBEDED_SCRIPTS.append(fybq)

# __include_embedded_script()

def import_cls(name, path) -> ScriptDef:
    import importlib.util
    spec = importlib.util.spec_from_file_location(name, path)
    foo = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(foo)
    script_def = foo.export
    script_def.name = name
    return script_def

def load_scripts(parent_dir):
    flow_cls = [] + EMBEDED_SCRIPTS
    for path, dir_list, file_list in os.walk(parent_dir):
        for file in file_list:
            if file.startswith("__init__"): continue
            if file.endswith(".py") or file.endswith(".pyd"):
                script_def = import_cls(file[:-3], os.path.join(path, file))
                flow_cls.append(script_def)
    return flow_cls